var express = require('express');
var router = express.Router();
var _ = require('underscore');

/* GET users listing. */
router.get('/act/guild_popularity', function(req, res, next) {
  // res.setHeader('Access-Control-Allow-Origin', '*');
  //res.send('../ajax.html');
  res.jsonp({
		code: 0,
		data: {
		    user_role: 1,  
		    is_signup:1,    
		    user_ID:1000, 
		    guild_ID:3000, 
		    guild_name:"青龙帮", 
		    guild_popularity_value:{ 
		      today:100, 
		      total:1200  
		    },
		    guild_activity_value:{ 
		      today:600, 
		      total:2000 
		    },
		    create_time:1456635024,
		    signup_time:1456388884
		},
	    msg: "OK"
   });  
});

router.get('/act/guild_popularity_signup', function(req, res, next) {
  res.setHeader('Access-Control-Allow-Origin', '*');
  //res.send('../ajax.html');
  res.jsonp({
		code: 0,
		data: {
		    user_role: 1,  
		    is_signup:1,    
		    user_ID:1000, 
		    guild_ID:3000, 
		    guild_name:"青龙帮", 
		    guild_popularity_value:{ 
		      today:100, 
		      total:1200  
		    },
		    guild_activity_value:{ 
		      today:600, 
		      total:2000 
		    },
		    create_time:1456635024,
		    signup_time:1456388884
	    },
	    msg: "OK"
   });  

});

router.get('/game/areav2', function(req, res, next) {
	const debug = req.query.debug
    const areaJson =  
    {
	    code: 0,
	    data: {
	        game_activity: [
	            {
	                activity_title: "风云",
	                banner: "http://7oxgb1.com2.z0.glb.qiniucdn.com/o_1a9mtvndaag12fhsiolu39pvb.png",
	                detail_href: "www.baidu.com",
	                identification: "0000000004@game",
	                offer_desc: "风云游戏的福利活动详细描述",
	                offer_notes: "风云游戏的福利活动优惠备注",
	                time_begin: 1453478400,
	                time_end: 1454169600,
	                time_now: 1473126311
	            },
	            {
	                activity_title: "下载有奖",
	                banner: "http://7oxgb1.com2.z0.glb.qiniucdn.com/o_1a9rlha071lno19c017khf241a6nb.png",
	                detail_href: "www.baidu.com",
	                identification: "0000000008@game",
	                offer_desc: "www.baidu.com",
	                offer_notes: "www.baidu.com",
	                time_begin: 1453737600,
	                time_end: 1454169600,
	                time_now: 1473126311
	            }
	        ],
	        game_first_charge: {
	            charge: 28,
	            diamond: 0,
	            product_id: 45,
	            time_end: 1532966400
	        },
	        game_notice: [
	            {
	                create_time: 1532966400,
	                id: 100,
	                system: 1,
	                title: "TT8月份全民公会争霸赛获奖名单新鲜出炉",
	                update_time: 1532966400,
	                url: "http://activity.52tt.com/yunying/ghzb826md/"
	            },
	            {
	                create_time: 1532966400,
	                id: 101,
	                system: 1,
	                title: "TT8月份全民公会争霸赛获奖名单新鲜出炉",
	                update_time: 1532966400,
	                url: "http://activity.52tt.com/yunying/ghzb826md/"
	            },
	            // {
	            //     create_time: 1532966400,
	            //     id: 102,
	            //     system: 1,
	            //     title: "TT8月份全民公会争霸赛获奖名单新鲜出炉",
	            //     update_time: 1532966400,
	            //     url: "http://activity.52tt.com/yunying/ghzb826md/"
	            // }
	        ],
	        game_open_service: [
	            {
	                id: 987,
	                open_time: 1473079320,
	                open_zone: "厄俄斯"
	            },
	            {
	                id: 988,
	                open_time: 1473079320,
	                open_zone: "阿里"
	            },
	            {
	                id: 986,
	                open_time: 1473076620,
	                open_zone: "逆夹书院"
	            }
	        ],
	        game_profile: {
	            cid: 366,
	            circle_master: "活在内网的圆可可",
	            circle_uri: "tt://navigation/circle/366",
	            create_time: "计费内测",
	            description: "马荣成正版授权3D版武侠《风云》手游强势袭来，原著港漫武侠IP的经典和强大毋庸置疑，兄弟一起，热血到底，经典重出江湖，原班人马融入游戏打造经典对话。攀爬第一楼、收益中华阁、战麒麟夺神兵，四大职业各具特色，初始剧情带你回到过去。帮会之战让大家重温经典、热血再起。 ",
	            download_times: 571,
	            download_total: 571,
	            download_url: "http://down.52tt.com/gamed?game_id=206606131&chnl_id=100&cp_id=T100",
	            focus_total: 173,
	            gid: 237539,
	            guild_total: 3,
	            guild_uri: "tt://navigation/guild/风云2/237539/3",
	            icon_url: "http://p0.qhimg.com/t013afc0ca5203c3bfd.png",
	            is_follow: 0,
	            name: "风云2",
	            package_name: "com.aorong.fish.tt",
	            package_size: "14534160",
	            status: 2,
	            status_str: "计费内测",
	            tag: [
	                {
	                    id: 2,
	                    title: "武侠"
	                },
	                {
	                    id: 7,
	                    title: "Run"
	                },
	                {
	                    id: 10,
	                    title: "塔防"
	                },
	                {
	                    id: 11,
	                    title: "RPG"
	                }
	            ],
	            topic_total: 7,
	            discussion_group:{
	            	 total_person:1,
	            	 url:''
	            }
	        },
	        game_screenshot: {
	            list: [
	                {
	                    type: 1,
	                    url: "http://7oxgb1.com2.z0.glb.qiniucdn.com/o_1a4sd1jngib1makier1msqaiga.jpg"
	                },
	                {
	                    type: 1,
	                    url: "http://7oxgb1.com2.z0.glb.qiniucdn.com/o_1a4sd1mgp131h1nh51envbb61vcff.jpg"
	                },
	                {
	                    type: 1,
	                    url: "http://7oxgb1.com2.z0.glb.qiniucdn.com/o_1a4sd1opq1l7ak8m5q95j41jt4k.jpg"
	                },
	                {
	                    type: 1,
	                    url: "http://7oxgb1.com2.z0.glb.qiniucdn.com/o_1a4sd1qpsk311mli1e2t1mbg15i0p.jpg"
	                },
	                {
	                    type: 1,
	                    url: "http://7oxgb1.com2.z0.glb.qiniucdn.com/o_1a4sd1sit1rkh8gl1kd19151idgu.jpg"
	                }
	            ],
	            total: 5
	        },
	        game_hotguild_list:[ 
	        	{
	        		id:1212,
                    icon_url:'http://7xold5.media1.z0.glb.clouddn.com/o_1aah0v52fi8ceemka1a41elf.jpg',
					descption:122323,
					level:1212,
					name:1212
                },
                {
	        		id:12123,
                    icon_url:'http://7xold5.media1.z0.glb.clouddn.com/o_1aah0v52fi8ceemka1a41elf.jpg',
					descption:122323,
					level:1212,
					name:1212
                },
                {
	        		id:12124,
                    icon_url:'http://7xold5.media1.z0.glb.clouddn.com/o_1aah0v52fi8ceemka1a41elf.jpg',
					descption:122323,
					level:1212,
					name:1212
                },
	        ],
	        game_video: {
	            list: [
	                {
	                    name: "电影级武侠手游来袭",
	                    snapshot: "http://7xold5.media1.z0.glb.clouddn.com/o_1a4si2p70ftq1qse1j8dr3lf9na.mp4?vframe/jpg/offset/3/w/180/h/100",
	                    type: 1,
	                    url: "http://7xold5.media1.z0.glb.clouddn.com/o_1a4si2p70ftq1qse1j8dr3lf9na.mp4"
	                }
	            ],
	            total: 1
	        },
	        giftpkg_profile: {
	            has_fetched: 0
	        },
	        guest_mode: 0,
	        lotto_profile: {
	            charge: 50,
	            time: 1
	        },
	        time_now: 1473126311
	    },
	    msg: "OK"
	};
   	res.setHeader('Access-Control-Allow-Origin', '*');
   	debug == '1' && res.json(areaJson)
  	res.jsonp(areaJson);  
});
router.get('/act/scratchcard/lottery_profile',function(req , res ,next){
	res.setHeader('Access-Control-Allow-Origin', '*');
	res.jsonp({
		code: 0,
		data: {
			profile: {
				banner: "http://obsiq8rn7.bkt.clouddn.com/tou.jpg",
				bg_color: "#ffffff",
				game_icon: "http://7oxgb1.com2.z0.glb.qiniucdn.com/o_1apkg2g68ju823018lldh1s4617.png?imageView2/1/w/120/h/120&imageView2/1/w/144/h/144/format/jpg/q/90",
				game_name: "御龙在天12",
				lottery_counts: 1,
				packages_pic: "http://7oxgb1.com1.z0.glb.clouddn.com/act/scratchcard_295288/award.jpg",
				rules_pic: "http://obsiq8rn7.bkt.clouddn.com/db_wenzi-.jpg"
			},
			result_item_list: [
				{
		            id: 1, //奖品id
		            type: 1, //代金券
		            describe_text: '激活大礼包',  //奖品描述文字
		            describe_pic: '',  //奖品描述图片
		            describe_detail:'如获奖励在活动结束后5个工作日内发放' //奖品详细描述领取时间等
		        },
		        {
		            id: 2, //奖品id
		            type: 1, //代金券
		            describe_text: '激活大礼包',  //奖品描述文字
		            describe_pic: '',  //奖品描述图片
		            describe_detail:'如获奖励在活动结束后5个工作日内发放' //奖品详细描述领取时间等
		        },
			 ],
			record_item_list: [
				{
		            id:1,
		            url:'http://obsiq8rn7.bkt.clouddn.com/p1.jpg'
		        },
		        {
		            id:2,
		            url:'http://obsiq8rn7.bkt.clouddn.com/p2.jpg'
		        },
		         {
		            id:3,
		            url:'http://obsiq8rn7.bkt.clouddn.com/p3.jpg'
		        },
		         {
		            id:4,
		            url:'http://obsiq8rn7.bkt.clouddn.com/p4.jpg'
		        },
		         {
		            id:5,
		            url:'http://obsiq8rn7.bkt.clouddn.com/p5.jpg'
		        },
		         {
		            id:6,
		            url:'http://obsiq8rn7.bkt.clouddn.com/p6.jpg'
		        }
			 ]
		},
		msg: "ok"
	})
})

router.post('/init/act/uploadimage',function(req , res , next){
	res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('X-Content-Type-Options','nosniff');
    console.log(req.body);
    res.json({
      code:0,
      data:
        [
          {"path":"周杰伦 - 告白气球.mp3","size":8624568,"name":"周杰伦 - 告白气球.mp3","date":"2016-08-04"},
          {"path":"周杰伦 - 前世情人.mp3","size":3322808,"name":"周杰伦 - 前世情人.mp3","date":"2016-08-04"},
          {"path":"周杰伦 - 前世情人(1).mp3","size":3210631,"name":"周杰伦 - 前世情人(1).mp3","date":"2016-08-04"},
          {"path":"周杰伦 - 说走就走 (1).flac","size":57877274,"name":"周杰伦 - 说走就走 (1).flac","date":"2016-08-04"},
          {"path":"周杰伦 - 说走就走.flac","size":57877274,"name":"周杰伦 - 说走就走.flac","date":"2016-08-04"},
          {"path":"周杰伦 - 英雄.flac","size":26028721,"name":"周杰伦 - 英雄.flac","date":"2016-08-04"},
          {"path":"走钢索的人.mp3","size":2886531,"name":"走钢索的人.mp3","date":"2016-08-04"}
        ]
    })  
})

router.get('/init/act/uploadinfo',function(req , res , next){
	res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('X-Content-Type-Options','nosniff');
    res.jsonp({
      code:0,
      data:
        { 
        	list:[
	        	{ 
	        		url:"FvOi_wKZr8A3Q2AbSA7JvCoFcteI",
	        		id:12,
	        		type:2
	        	},
	        	{ 
	        		url:"FvOi_wKZr8A3Q2AbSA7JvCoFcteI",
	        		id:13,
	        		type:2
	        	}
	        ],
	        total:1212
    	},
    	msg:'ok'
    })  
})

/* GET users listing. */
router.get('/game/order_benefits', function(req, res, next) {
  res.setHeader('Access-Control-Allow-Origin', '*');
  //res.send('../ajax.html');
  const query = req.query
  console.log(query)
  
	 const obj = {
		code: 0,
		data: {
			list:[],
			total:20,
		    server_time:new Date().getTime()
		},
	    msg: "OK"
   }
    const Things = 5
	for (var i = 0; i < Things; i++) {
		const items = {
			gid:0,
			icon:'http://7oxgb1.com2.z0.glb.qiniucdn.com/o_1alpamn081n38q5g1fdo13ri29f17.png',
			game_name:'功夫熊猫',
			description:'砧板收取物色到季后赛的几乎是附近开会的高房价是飞机客户说房价',
			tag:[
				{id:1,title:"ARPG"},
				{id:2,title:"ARPG"},
				{id:3,title:"ARPG"}
			],
			status_order:0,
			is_order:1,
			order_times:0,
			game_video:{
				list:[{
					name: "",
					snapshot: "http://7xold5.media1.z0.glb.clouddn.com/o_1aah0v52fi8ceemka1a41elfa.mp4?vframe/jpg/offset/3/w/180/h/100",
					url: "http://7xold5.media1.z0.glb.clouddn.com/o_1aah0v52fi8ceemka1a41elfa.mp4",
					type:"1"
				}],
				total:1
			},
			game_screenshot:{
				list:[
					{
						url: "http://7oxgb1.com2.z0.glb.qiniucdn.com/o_1at5drtsp2ul6v91kb4551pnpe.jpg",
						type:"1"
					},
					{
						url: "http://7oxgb1.com2.z0.glb.qiniucdn.com/o_1at5drtsp2ul6v91kb4551pnpe.jpg",
						type:"1"
					},{
						url: "http://7oxgb1.com2.z0.glb.qiniucdn.com/o_1at5drtsp2ul6v91kb4551pnpe.jpg",
						type:"1"
					}
				],
				total:1
			},
			gift_list:[
				{
					icon:'http://7oxgb1.com2.z0.glb.qiniucdn.com/o_1alpamn081n38q5g1fdo13ri29f17.png',
					gift_name:'天狙杀天狙杀天狙杀',
					number:12
				},
				{
					icon:'http://7oxgb1.com2.z0.glb.qiniucdn.com/o_1alpamn081n38q5g1fdo13ri29f17.png',
					gift_name:'我说的后视',
					number:23
				},
				{
					icon:'http://7oxgb1.com2.z0.glb.qiniucdn.com/o_1alpamn081n38q5g1fdo13ri29f17.png',
					gift_name:'天狙杀3',
					number:23
				}
			],
			activity_url:'https://www.baidu.com/'
		}
		items.gid = i 
		items.game_name = '我去'+i*Math.random()
		const findLastIndex = _.findLastIndex(obj.data.list,function(obj) {
	        return obj.gid === items.gid
	     });
		if(findLastIndex !== -1){
			obj.data.list.splice(findLastIndex,1,items)
		}else{
			obj.data.list.push(items)
		}
	}
  const  debug = query.debug
  debug == 0 ?  res.jsonp(obj) :  res.json(obj)

});

module.exports = router;
